#include "StdAfx.h"
#include "UIMemWindowDC.h"


CUIMemWindowDC::CUIMemWindowDC( HDC hDC, const RECT& rect ): m_bmpOrignMem( NULL ),
    m_bmpOldOrignMem( NULL ), m_dcMem( NULL )
{
    ::CopyRect( &m_rect, &rect );
    m_hDC = hDC;
    m_dcMem =::CreateCompatibleDC( hDC );
    m_bmpOrignMem =::CreateCompatibleBitmap( hDC, m_rect.right - m_rect.left, m_rect.bottom - m_rect.top );
    m_bmpOldOrignMem = ( HBITMAP )::SelectObject( m_dcMem, m_bmpOrignMem );
}

CUIMemWindowDC::~CUIMemWindowDC( void )
{
    ::BitBlt( m_hDC, m_rect.left, m_rect.top, m_rect.right - m_rect.left, m_rect.bottom - m_rect.top, m_dcMem, m_rect.left, m_rect.top, SRCCOPY );
    ::SelectObject( m_dcMem, m_bmpOldOrignMem );
    ::DeleteObject( m_bmpOldOrignMem );
    ::DeleteObject( m_bmpOrignMem );
    ::DeleteObject( m_dcMem );
}

void CUIMemWindowDC::ExcludeClient( HWND hWnd )
{
    RECT rcWnd;
    ::GetWindowRect( hWnd, &rcWnd );
    POINT pt;
    pt.x = rcWnd.left;
    pt.y = rcWnd.top;
    ::ScreenToClient( hWnd, &pt );
    pt.x = 0 - pt.x;
    pt.y = 0 - pt.y;
    RECT rcClient;
    ::GetClientRect( hWnd, &rcClient );
    ::ExcludeClipRect( m_hDC, pt.x, pt.y, pt.x + rcClient.right, pt.y + rcClient.bottom );
}

HDC CUIMemWindowDC::GetDC()
{
    return m_dcMem;
}
